﻿using System;
using System.Web.UI;
using mojoPortal.Web.RS.SBM.AppCode.Lib;

 
namespace mojoPortal.Web.RS.SBM
{
    public partial class RSInvoiceDetail : RSBasePage
    {
        int _companyid = 0;
        int _locationid = 0;
        int _invoiceid = 0;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                InitializeReadyServicePage("Invoice Detail");
                RSUserIdentity userIdentity = GetRSUserIdentity();
                _companyid = userIdentity.RSCompanyId;

                if (Request.QueryString["invoiceid"] != null)
                {
                    _invoiceid = Convert.ToInt32(Request.QueryString["invoiceid"].ToString());
                    _locationid = RSSBMCommonFunctions.GetLocationIDByInvoiceID(_companyid, _invoiceid);
                }

                if (_companyid > 0 && _locationid > 0)
                {
                    ucLocationHeaderControl.LoadLocationHeader(_companyid, _locationid);
                    ucInvoiceControl.LoadInvoiceDataByID(_companyid, _invoiceid);
                    //bool hasData = ucInvoiceControl.LoadInvoiceDataByID(_companyid, _invoiceid);
                    //if (hasData)
                    //{
                    //    ucPaymentListControl.LoadInvoicePaymentList(_companyid, _invoiceid);
                    //}
                }
            }
        }

        private void ActiveTabChanged(int invoiceid)
        {
            if (invoiceid > 0)
            {
                switch (tcInvoiceDetail.ActiveTabIndex)
                {
                    case 0:
                        //Response.Redirect("RSInvoiceDetail.aspx?invoiceid=" + invoiceid);
                        break;
                    case 1:
                        Response.Redirect("RSInvoicePayments.aspx?invoiceid=" + invoiceid);
                        break;

                    //default:
                }
            }

        }

        protected void tcInvoiceDetail_OnActiveTabChanged(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["invoiceid"]))
                _invoiceid = Convert.ToInt32(Request.QueryString["invoiceid"].ToString());

            ActiveTabChanged(_invoiceid);
        }
    }
}